#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>

struct abp { int a; int b; int p; };

bool operator>=(abp const & a, abp const & b)
{
	return (a.a >= b.a && a.b <= b.b);
}

int const maxn = 50007;
int const inf = 1 << 27;
int from[maxn];
int max_len[maxn];
abp da[maxn];
int n;

void print(int len)
{
	for (int i = 0; i < n; i++)
		if (max_len[i] == len) {
			std::printf("%d", i + 1);
			for (i = from[i]; i < n; i = from[i]) {
				std::printf(" %d", i + 1);
			}
			std::printf("\n");
			return;
		}
}

int main()
{
	while (std::scanf("%d", &n) != EOF) {
		for (int i = 0; i < n; i++) std::scanf("%d", &da[i].a);
		for (int i = 0; i < n; i++) std::scanf("%d", &da[i].b);
		for (int i = 0; i < n; i++) da[i].p = i;

		std::vector<std::vector<abp> > q(n + 2);
		int q_r = 1;
		abp len0; len0.a = -inf; len0.b = inf; len0.p = n;
		q[0].push_back(len0);
		max_len[n] = 0;

		abp len1; len1.a = da[n-1].a; len1.b = da[n-1].b; len1.p = da[n-1].p;
		from[n-1] = n;
		q[1].push_back(len1);
		max_len[n-1] = 1;

		for (int i = n-2; i >= 0; i--) {
			int l = 0, r = q_r;
			while (l + 1 < r) {
				int mid = (l + r) / 2;
				if (da[i] >= q[mid][q[mid].size() - 1]) l = mid;
				else				 					r = mid - 1;
			}
			if (da[i] >= q[r][q[r].size() - 1]) l = r;
			if (l + 1 > q_r) q_r = l + 1;

			// find pos
			int ll = 0, rr = q[l].size() - 1;
			while (ll + 1 < rr) {
				int mid = (ll + rr) / 2;
				if (da[i] >= q[l][mid]) ll = mid;
				else					rr = mid - 1;
			}
			if (!q[l].empty() && da[i] >= q[l][rr]) ll = rr;
			from[i] = q[l][ll].p;

			max_len[i] = l + 1;
			q[l + 1].push_back(da[i]);
		}

		std::printf("%d\n", q_r);

		for (int i = 0; i < n; i++) std::cerr << from[i] << ' ';
		std::cerr << '\n';
		for (int i = 0; i < n; i++) std::cerr << max_len[i] << ' ';
		std::cerr << '\n';

		print(q_r);
	}
}

